<template>
	<div class="wy-main business-car-manage wei_business_car_manage">
		<a-row class="wy-main-title">
			<a-col :span="24">
				<p class="title-p">
					<a-divider class="title-vertical"  type="vertical" />
					<span class="title-span" >管理物流招标信息</span>
					<a-divider class="title-divider"  />
				</p>
			</a-col>
		</a-row>
		<div>
			<a-input v-model="tendTitle" placeholder='请输入招标标题' style="width: 200px;"/>
			<a-button type="primary" style="margin-left: 10px;" @click="gettenderinginfo">点击查询</a-button>
			<a-button style="margin-left: 10px;" @click="reset">重置信息</a-button>
			<!--<router-link to="/matching/tendering/publish"><a-button style="float: right;" type="primary" >发布物流招标信息</a-button></router-link>-->
			<router-link to="/matching/tendering/publish">
				<a-button type="primary" class="wy-m-l-10 wy-float-r"  v-hasPermission="'Tendering:add'">发布物流招标信息</a-button>
			</router-link>
			<a-button type="primary" class="wy-m-l-10 wy-float-r"  v-hasPermission="'Tendering:add2'" @click="$refs.autoError.handleShow()">发布物流招标信息</a-button>
			
		</div>
		<div class="route_choice wei_route_choice">
			<a-table :columns="columns" :dataSource="data" :rowKey="record => record.tendId" :pagination="pagination" :loading="loading" @change="handleTableChange" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}">
				<span slot="name" slot-scope="text1">
				  <span>{{text1.address1}}--→{{text1.address2}}</span>
			    </span>
			   	<span slot="approvalStatus" slot-scope="text,record">
				  		<span class="wei_warning" v-if="record.approvalStatus==106">审核中</span>
				  		<span class="wei_primary" v-if="record.approvalStatus==107">审核通过</span>
				  		<span class="wei_danger" v-if="record.approvalStatus==108">审核失败</span>
			    </span>
			    <span slot="tendStatused" slot-scope="text,record">
				  		<span class="wei_warning" v-if="record.tendStatus==0">招标中</span>
				  		<span class="wei_primary" v-if="record.tendStatus==1">招标已完成</span>
				  		<span class="wei_danger" v-if="record.tendStatus==2">招标失败</span>
			    </span>
			    <span slot="fromCity" slot-scope="text,record">
				  		<span>{{record.fromProvince}}{{record.fromCity}}</span>

			    </span>
			    <span slot="toCity" slot-scope="text,record">
				  		<span>{{record.toProvince}}{{record.toCity}}</span>

			    </span>
				<span slot="operation" slot-scope="text, record">
			      <a href="javascript:;" @click='seeInfo(record)'>查看</a>
<!-- 			      <a-divider type="vertical" /> -->
			      <a href="javascript:;" @click='editInfo(record)' v-if="record.approvalStatus == '108'" >编辑</a>
			      <!-- <a-divider type="vertical" v-if="record.approvalStatus == '108'"  /> -->
			      <a href="javascript:;" @click='delDriver(record)'>删除</a>
			      <!-- <a-divider type="vertical" /> -->
			      <a href="javascript:;"  @click='pushNotuce(record)'>中标公示</a>
			    </span>
			</a-table>
		</div>
		<div style='margin-top: -50px;'>
			<a-button @click="delDrivers">删除所选</a-button>
		</div>
		<a-modal :title="type=='edit'?'编辑':'查看信息'" :type="type" :visible="visible" @cancel="handleCancel" width="700px" :maskClosable='false' :footer="null" >
			<publish-add v-if="visible" :datail='datail' :isSee="isSee" :type="type" @change="editFormChange"></publish-add>
		</a-modal>
		<a-modal title="中标信息" :visible="showPush" @cancel="close"  :maskClosable='false' :footer="null" >
			<a-form :form="form" @submit="handleSubmit" class="wy-form" style="padding-bottom: 20px;">
				<a-form-item  :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }"  label="招标编号">
					<a-input disabled="disabled" v-decorator="[ 'tendNo']" />
				</a-form-item>
				<a-form-item  :label-col="{ span: 6}" :wrapper-col="{ span: 16 }"  label="中标企业">
					<a-input :disabled="disNo" v-decorator="[ 'winningCompany', { rules: [ {required: true, message: '中标企业不能为空！',}]}]" />
				</a-form-item>
				<a-form-item  :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }"  label="中标金额">
					<a-input-number :disabled="disNo" :min="0.01" :precision='2' size="large" style='width: 70%;' v-decorator="[ 'winningMoney', { rules: [ {required: true, message: '中标金额不能为空！',}]}]" placeholder='请输入中标金额' />
					<span style="margin-left: 10px;">万元</span>
				</a-form-item>
				<div class="ant-row ant-form-item" >
					<div class="ant-col-6 ant-form-item-label"></div>
					<div class="ant-col-10 ant-form-item-control-wrapper">
						<div class="ant-form-item-control">
							<span class="ant-form-item-children">
							<a-button type="primary"  html-type="submit" style="width: 280px;height:50px;margin-top: -10px;">确认并发布</a-button>
						</span>
						</div>
					</div>
				</div>
			</a-form>
		</a-modal>
		<!--未认证弹窗-->
		<auto-error  ref="autoError" ></auto-error>
	</div>
</template>
<script>
	import publishAdd from './Publish'
	import AutoError from '@/components/dialog/AutoError'
	const columns = [{
		title: '招标标题',
		dataIndex: 'tendTitle',
		key: 'tendTitle',
		scopedSlots: {
			customRender: 'tendTitle'
		},
	}, {
		title: '招标区域(出发地)',
		dataIndex: 'fromCity',
		key: 'fromCity',
		scopedSlots: {
			customRender: 'fromCity'
		}
	},{
		title: '招标区域(到达地)',
		dataIndex: 'toCity',
		key: 'toCity',
		scopedSlots: {
			customRender: 'toCity'
		}
	},  {
		title: '审核状态',
		dataIndex: 'approvalStatus',
		key: 'approvalStatus',
		scopedSlots: {
			customRender: 'approvalStatus'
		},
	}, {
		title: '招标状态',
		key: 'tendStatusName',
		dataIndex: 'tendStatusName',
		scopedSlots: {
			customRender: 'tendStatused'
		},
	},
	{
		title: '发布日期',
		key: 'createTime',
		dataIndex: 'createTime',
	}, {
		title: '操作',
		key: '6',
		scopedSlots: {
			customRender: 'operation'
		},
	}];

	export default {
		data() {
			return {
				disNo:false,
				datail:{},
				type:'',
				isSee:true,
				visible:false,
				showPush:false,
				tendTitle:'',
				data:[],
				columns,
				loading: false,
				pagination: {
				  pageSizeOptions: ['10', '20', '30', '40', '100'],
				  defaultCurrent: 1,
				  defaultPageSize: 10,
				  total:0,
				  showSizeChanger: true,
				  showTotal: (total, range) => `共 ${total} 条记录`
				},
				form: this.$form.createForm(this),
			    selectedRowKeys: [],
			    // 当前选中投标内容
			    detail: {}
			}
		},
		computed: {
		},
		beforeCreate() {},
		created() {
			this.gettenderinginfo()
		},
		components: {
			publishAdd,
			AutoError
			
		},
		watch: {},

		mounted: function() {

		},
		methods: {
			editFormChange(){
				console.log('editFormChange::',this.visible)
				this.visible = false
			},
			// 确认发布中标
			handleSubmit(e){
				if(this.loading) return;
				e.preventDefault();
				this.form.validateFieldsAndScroll((err, values) => {
					if(!err) {
						// this.$notification.error({
						// 	  message: '暂时无法发布，详情请联系后台',
						// });
						this.loading = true;
						console.log('Received values of form: ', values);
						values.tendId = this.detail.tendId
						values.tendStatus = 1
						this.$put('info/logisticsTenderee', values,true).then((r) => {
							if(r.status == 200){
								this.$message.success(r.data.message);
								this.form.resetFields();
								this.showPush = false
								this.gettenderinginfo()
							}else{
								this.$message.error(r.data.message);
							}
							this.loading = false;
						}).catch((e) => {
							this.loading = false;
						})
					}
				});
			},
			// 打开中标公示
			pushNotuce(data){
				this.showPush = true
				this.detail = data
				if(data.winningCompany){
					this.disNo = true
				}else{
					this.disNo = false
				}
				setTimeout(()=>{
					this.form.setFieldsValue({
						tendNo: data.tendNo,
						winningCompany: data.winningCompany,
						winningMoney: data.winningMoney
					});
		        },0)
			},
			// 关闭中标公示
			close(){
				this.showPush = false
			},
			// 查看货物信息
			seeInfo(data){
				this.type = "find";
				this.isSee = true;
				this.visible = true
		        this.datail = data
			},
			//修改货物信息
			editInfo(data){
				this.type = "edit";
				this.isSee = false;
				this.visible = true
		        this.datail = data
			},
			// 关闭弹窗
			handleCancel(){
				this.visible = false
			},
			// 重置信息
			reset(){
				this.tendTitle = ''
				this.gettenderinginfo()
			},
			// 获取招标信息
			gettenderinginfo(params={}){
				this.loading = true
				params.tendTitle = this.tendTitle
				params.pageSize = this.pagination.defaultPageSize
				params.pageNum = this.pagination.defaultCurrent
				this.$get('/info/logisticsTenderee', params).then((r) => {
					console.log(r)
					this.loading = false
					this.data = r.data.data.rows
					this.pagination.total = r.data.data.total
				})
			},
			// 删除多条信息
			delDrivers(){
				 if (!this.selectedRowKeys.length) {
				  this.$message.warning('请选择需要删除的记录')
				  return
				}
				let that = this
				this.$confirm({
				  title: '确定删除所选中的记录?',
				  content: '当您点击确定按钮后，这些记录将会被彻底删除',
				  centered: true,
				  onOk () {
				    let logIds = that.selectedRowKeys
					that.$delete('/info/logisticsTenderee/' + logIds.join(',')).then(() => {
					  that.$message.success('删除成功')
					  that.selectedRowKeys = []
					  that.gettenderinginfo()
					})
				  },
				  onCancel () {
				    that.selectedRowKeys = []
				  }
				})
			},
			// 删除单条信息
			delDriver(data){
				console.log(data)
				let that = this
				this.$confirm({
				  title: '确定删除所选中的记录?',
				  content: '当您点击确定按钮后，这些记录将会被彻底删除',
				  centered: true,
				  onOk () {
				    let logIds = []
				    logIds.push(data.tendId)
				    that.$delete('/info/logisticsTenderee/' + logIds.join(',')).then(() => {
				      that.$message.success('删除成功')
				      that.selectedRowKeys = []
				      that.gettenderinginfo()
				    })
				  },
				  onCancel () {
				    that.selectedRowKeys = []
				  }
				})
			},
			
			// 全选事件
			onSelectChange (selectedRowKeys) {
		      console.log('selectedRowKeys changed: ', selectedRowKeys);
		      this.selectedRowKeys = selectedRowKeys
		    },
			// 表格排序 分页 筛选事件
			handleTableChange (pagination, filters, sorter) {	
				this.pagination.defaultPageSize = pagination.pageSize
				this.pagination.defaultCurrent = pagination.current
			   	this.gettenderinginfo()
			},
		}
	}
</script>

<style lang="less" scoped>

</style>